﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace ImageEditor
{
    class ImageManager
    {

        public ImageManager() { }

        private static Bitmap GenerateBorder(Bitmap map, Color borderColor)
        {
            for (int x = 0; x < map.Width; x++)
            {
                for (int y = 0; y < map.Height; y++)
                {
                    if ((x > 0 && y > 0) && (x < map.Width - 1 && y < map.Height - 1))
                    {
                        // Set top border
                        if (map.GetPixel(x, y).Equals(Color.FromArgb(192, 192, 192)) &&
                               (!map.GetPixel(x, y - 1).Equals(Color.FromArgb(192, 192, 192)) && !map.GetPixel(x, y - 1).Equals(borderColor)))
                        {
                            map.SetPixel(x, y - 1, borderColor);
                        }
                        // Left
                        if (map.GetPixel(x, y).Equals(Color.FromArgb(192, 192, 192)) &&
                               (!map.GetPixel(x - 1, y).Equals(Color.FromArgb(192, 192, 192)) && !map.GetPixel(x - 1, y).Equals(borderColor)))
                        {
                            map.SetPixel(x - 1, y, borderColor);
                        }
                        // Bottom
                        if ((!map.GetPixel(x, y).Equals(Color.FromArgb(192, 192, 192)) && !map.GetPixel(x, y).Equals(borderColor)) &&
                               (map.GetPixel(x, y - 1).Equals(Color.FromArgb(192, 192, 192))))
                        {
                            map.SetPixel(x, y, borderColor);
                        }
                        //Right
                        if ((!map.GetPixel(x, y).Equals(Color.FromArgb(192, 192, 192)) && !map.GetPixel(x, y).Equals(borderColor)) &&
                                (map.GetPixel(x - 1, y).Equals(Color.FromArgb(192, 192, 192))))
                        {
                            map.SetPixel(x, y, borderColor);
                        }
                    }
                }
            }
            return map;
        }

        private static void SaveEditedImages(Bitmap map, String fileName)
        {
            Image image = (Image)map;
            image.Save(fileName);
        }
    }
}
